<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen"
	href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen"
	href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
	<div>
		<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div>
				<header style="height: 100%">
					<div align="left">
						<table style="width: 100%">
							<tr>
								<td>
									<form class="form-inline" onsubmit="return false">
										<div class="form-group">
											素材类型：
											<select id="adType">
												<option value="">全部</option>
											</select>
											关键字： <input id="keywords" type="text" class="form-control" placeholder="素材名称">
											<button id="searchBt" class="layui-btn layui-btn-sm">
												<i class="layui-icon">&#xe615;</i>搜索
											</button>
										</div>
									</form>
								</td>
								<td align="right">
									<button type="button" class="layui-btn" id="test1"
										onclick="addFiles('addContent.html')">
										<i class="layui-icon">&#xe67c;</i>上传素材
									</button>
								</td>
							</tr>
						</table>
					</div>
				</header>

				<div>
					<div class="widget-body no-padding">
						<table id="dt-table"
							class="table table-striped table-bordered table-hover"
							style="width: 100%">
							<thead>
								<tr>
								</tr>
								<tr>
									<th>ID</th>
									<th>素材名称</th>
									<th>素材大小</th>
									<th>素材类型</th>
									<th>分辨率</th>
									<th>状态</th>
									<th>上传人</th>
									<th>上传时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
layui.use([ 'layer' ], function() {
	var layer = layui.layer;
});
var pers = checkPermission();

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"ordering" : false,
        	"language": {
                "url": urlRootPrefix + "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : urlRootPrefix + "/hdContents",
        		"type":"get",
        		"data":function(d){
        			d.selectTypeId = $("#adType").val();
    				d.keywords = $("#keywords").val();
    			},
    			"dataSrc" : function(data) {
  				  //自定义错误拦截
   		          if(!data.success && !isNotBlank(data.recordsTotal)){
   		           	layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
   					return [];
   				  }
   		          return data.data;
    			} 
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{ "data": "indexId", "defaultContent": ""},
				{ "data": "adName", "defaultContent": ""},
				{ "data": "adSize", "defaultContent": "",
					"render": function (data, type, row) {
                        return data < (1024*1024)?eval(data / 1024).toFixed(2)+"kb": eval(data / 1024/1024).toFixed(2)+"M";
                  	}
				},
				{ "data": "fileType", "defaultContent": "",
					"render": function (data, type, row) {
                        return row['adTypeName']+'-'+data;
                  	}
				},
				{ "data": "resolution", "defaultContent": ""},
				{ "data": "statusName", "defaultContent": "",
		         	"render": function (data, type, row) {
		         		var href = urlRootPrefix + "/pages/common/auditLogList.html?id="+row['adId'];
                        return "<a href='javascript:void(0);' style='color:#3276b1;' onclick='showWindow(\""+href+"\",\"操作日志\")'>"+data+"</a>";
      	            }		
				},
				{ "data": "createUserName", "defaultContent": ""},
				{ "data": "createTime", "defaultContent": ""},
                { 
                	"data": "", 
                	"defaultContent": "",
                	"orderable":false,
                	"render": function (data, type, row) {
                		var id = row['adId'];
                		var select = buttonSelect(urlRootPrefix + "/statics" + row['adUrl']);
                        var del = buttonDel(id, "release:adContent:del", pers);
                        var sub = row['status'] == '1'?buttonSub(id, "release:adContent:sub", pers):'';
                        var show = buttonShowHref("detailsAdContent.html?id="+id);
                        return select+show+del+sub;
                  	}
                },
                
            ],
           "order": [[ 3, "desc" ]]
        } );
}
function del(id){
	delIds([id]);
}
function delIds(ids){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'post',
            url : urlRootPrefix + '/hdContents/delete',
            contentType: "application/json; charset=utf-8",  
            data : JSON.stringify(ids),
            success : function(data) {
            	if(!data.success){
					layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					$("button[type='submit']").removeAttr("disabled");
					return;
				}
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}
function subId(id){
	subIds([id]);
}
function subIds(ids){
	layer.confirm('确定要提交审核吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'post',
            url : urlRootPrefix + '/hdContents/submit',
            contentType: "application/json; charset=utf-8",  
            data : JSON.stringify(ids),
            success : function(data) {
            	if(!data.success){
					layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					$("button[type='submit']").removeAttr("disabled");
					return;
				}
                example.ajax.reload();
                layer.msg("提交审核成功，请等待审核员审核吧");
            }
        });
        
        layer.close(1);
    });
}
$("#searchBt").click(function(){
	example.ajax.reload();
});

function addFiles(url) {
	layer.open({
		type : 2, //Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）,
		shade : 0.1, //遮罩层透明度
		area : [ '700px', '550px' ], //弹出层宽高
		title : '素材上传',//弹出层标题
		content : url
	//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
	});
}
function showFiles(url) {
	layer.open({
		type : 2, //Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）,
		shade : 0.1, //遮罩层透明度
		area : [ '700px', '550px' ], //弹出层宽高
		title : '详情与文件',//弹出层标题
		content : url
	//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
	});
}
function getAdType(){
   	$.ajax({
           type : 'get',
           url : urlRootPrefix + '/hdContents/listAdContentTypes',
           success : function(data) {
	           	if(!data.success){
	           		layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					return;
				}
	           	var data = data.data;
	           	var typeHtml = "";
	           	for(var i=0;i<data.length;i++){
	           		typeHtml += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
	           	}
	           	$("#adType").append(typeHtml);
           }
       });
}
getAdType();
init();

</script>